package uit.nfc.utils;

import java.util.ArrayList;

import uit.nfc.nfcmenudishes.IntroActivity;
import uit.nfc.nfcmenudishes.NfcMenuActivity;
import uit.nfc.nfcmenudishes.R;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.ArrayAdapter;

public class GetDishesByIdAsyncTask extends AsyncTask<Void, DishesItem, String> {

	private Context context;
	private String dishesId;
	private ProgressDialog progressDialog;
	private DishesItem dishes;
	
	public GetDishesByIdAsyncTask(Context context, String dishesId) {
		this.context = context;
		this.dishesId = dishesId;
	}
	
	@Override
	protected void onPreExecute() {
		this.progressDialog = ProgressDialog.show(context, "Loading...", "Please wait..."); 
	}

	@Override
	protected String doInBackground(Void... params) {
		String response = WebServiceHelper.callWebService("http://restaurant-webservice.appspot.com/resources/item/get/" + dishesId);
		return response;
	}

	@Override
	protected void onPostExecute(String result) {
		this.progressDialog.cancel();
		
		dishes = JSONParser.parseDishesItem(result);
		
		if (dishes != null) {
			((IntroActivity)context).getTextDishes().setText(dishes.getName());
			
			ImageDownloader imageDownloader = new ImageDownloader();
			imageDownloader.download(dishes.getImageLink(), ((IntroActivity)context).getImageView());
		}
	}

}
